﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using UnityEngine;

public class Honeycomb_30: Missile
{
    GameObject m_MultiFireShip;
    Vector3 m_MultiFirePosition;
    Vector3 m_MultiFireDirection;

    int m_MagazineSize = 0;
    int m_MagazineSizeMax = 30;
    float m_ShotVelocity = 0.16f;
    float m_ContinueFireTimeCount = 0;
    public Honeycomb_30()
    {
        m_Price = 999;
        m_Speciality = Speciality.RUIN;
        m_Type = ItemsType.WEAPON_MIDDLE_MISSILE_HONEYCOMB_30;
        ResearchInfluence = InfluenceMG.INFLUENCE_EARTH;
        m_DamageType = DamageType.TYPE_EXPLOSION;
        m_Level = Level.LEVEL_MIDDLE;
        ShutRange = 18;
        m_TrunVelocity = 60;
        ShutVelocity = 44.4f;
        BulletFlyVelocity = 4f;
        Damage = 25f;
        m_Hp = 5;
        m_ShotErrorValueBase = 130;
        m_DropRate = 0.05f;
        m_ShotErrorValueMax = 160;
        m_Acceleration = 10;
        Name = "蜂巢-30";
        Perview = "Textures/Weapon/WeaponMiddle/Honeycomb-30";
        WeaponResource = "Perfabs/Weapon/Middle/Honeycomb-30";
        BulletResource = "Perfabs/Bullet/Honey";
        m_FireAudioResouce = "Perfabs/Audio/PuHu";
        Description = "地联研发的导弹集群，能够在短时间发射超量的跟踪导弹。造成大面积杀伤，难以拦截，打着又疼是该武器的代名词。当发射过一轮之后，需要大量的时间填装下一次攻击。";

    }
    public override FlyItem Fire(GameObject ship, WeaponSlot slot, Vector3 position, Vector3 direction)
    {
        Slot = slot;
        m_MultiFireShip = ship;
        m_MultiFireDirection = direction;
        m_MagazineSize = m_MagazineSizeMax;
        return null;
    }

    public override int update()
    {
        base.update();

        if (m_MagazineSize > 0)
        {
            m_ContinueFireTimeCount += Time.deltaTime;
            if (m_ContinueFireTimeCount >= m_ShotVelocity)
            {
                m_MagazineSize--;
                m_ContinueFireTimeCount = 0;
                var flyItem = base.Fire(m_MultiFireShip, Slot, Slot.transform.position, Slot.CurrentWeaponDirection);
                MissileFunction missile = flyItem as MissileFunction;
                if (missile)
                {
                    missile.m_Trace = true;
                    if(ArmShip)
                        missile.m_Target = ArmShip.gameObject;
                }
            }
        }
        return 1;
    }
}